<?php
namespace app\index\controller;
use think\Controller;
use think\Db;

class Index extends Controller
{
    public function index()
    {
        return $this->fetch();
    }

    public function o_success(){
        return $this->fetch();
    }

    public function json_add_orders(){
        if (!$this->request->isPost()) {
            $this->error('错误的请求方式');
        }


        $name = $this->request->param('name','');
        if(empty($name)) {
            $this->error('收件人不能为空');
        }
        $city = $this->request->param('city','');
        if(empty($city)) {
            $this->error('省市区不能为空');
        }
        $address = $this->request->param('address','');
        if(empty($address)) {
            $this->error('地址不能为空');
        }
        $tel = $this->request->param('tel','');
        if(empty($tel)) {
            $this->error('手机号不能为空');
        }

        $checkbox1 = $this->request->param('checkbox1/a','');
        if(empty($checkbox1)) {
            $this->error('套餐至少选择一项');
        }

        $checkbox11 = $this->request->param('checkbox11/a','');
        if(empty($checkbox11)) {
            $this->error('请确认公告');
        }


        $data['name'] = $name;
        $data['city'] = $city;
        $data['address'] = $address;
        $data['mobile'] = $tel;
        $data['user_ip'] = $this->request->ip();
        $data['items'] = implode('<br>',$checkbox1);
        $data['create_time'] = time();
        Db::name('orders')->insert($data);


        $this->success('添加成功');
    }
}
